package com.google.code.swingonfire.plotter;

import java.awt.BasicStroke;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.Stroke;
import java.awt.geom.Path2D;

public class LunarSketch implements Sketch
{

    private static final Rectangle BOUNDS = new Rectangle(-8, -8, 16, 16);
    private static final Stroke STROKE = new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);

    private final double phase;

    public LunarSketch(double phase)
    {
        super();

        this.phase = phase;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Rectangle getBounds()
    {
        return BOUNDS;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void draw(Graphics2D g)
    {
        Path2D.Double path = new Path2D.Double();

        path.moveTo(0, -7);

        double d = (phase > 1) ? 18 * (2 - phase) : 18;
        path.curveTo(-9 + d, -6.5, -9 + d, 6.5, 0, 6.5);

        d = (phase < 1) ? 18 * phase : 18;
        path.curveTo(9 - d, 6.5, 9 - d, -6.5, 0, -6.5);

        g.fill(path);

        g.setStroke(STROKE);
        g.drawOval(-7, -7, 14, 14);
    }

}
